import {defineStore} from 'pinia'
import {ImgIdentifyResult} from "@/pojo/ImageIdentifyResult/ImgIdentifyResult.js";
import {ImageGeneralIdentify, ImageUnderstand} from "@/apis/ImageIdentify.js";
import {ImgUnderstandResult} from "@/pojo/ImageIdentifyResult/ImgUnderstandResult.js";

export const useImgIdentifyStore = defineStore("ImgIdentifyStore", () => {

    //图片识别结果
    const identifyResult = new ImgIdentifyResult()

    //图片理解结果
    const understandResult = new ImgUnderstandResult()


    const getImageIdentify = async (file) => {
        const formData = new FormData()
        formData.append('file', file);


        const res = await ImageGeneralIdentify(formData)
        identifyResult.parseJson(res);


    }


    const getImgUnderstand = async  (file, question) => {
        const formData = new FormData()
        formData.append('file', file);

        //开始请求
        const res = await ImageUnderstand(formData, question)

        //解析数据
        understandResult.parseJson(res)


        console.log(understandResult.description)
    }


    return {
        getImageIdentify,
        getImgUnderstand,

        identifyResult,
        understandResult
    }


}, {            //持久化存储，存储到了浏览器中的localStorage
    persist: true
})